﻿/** 忍者棒球
  游戏按键设定为:
  1-单发攻击, 2-跳跃, 3-ab宏

  增加了"瞬电"技能的宏优先级,保证不被打断

  By setycyas @2024-11-07
*/

/* 全局设定
*/
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\OrderMap.2.ahk"
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyEmu.2.ahk"

#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
SendMode("Input")
;SendMode("Event")

/* 制作忍者棒球的宏类
*/
class NbbatmanMacro extends CommonMacro {

  /* 新增的宏函数
  */
  _AB(key){
    this._down(2)
    this._down(1)
    sleep(60)
    this._up(1)
    sleep(20)
    this._up(2)
  }
  _前A(key){
    local face := this._face.face()
	  send("{" . face . " down}")
	  this._down(1)
	  sleep(50)
	  send("{" . face . " up}")
	  this._up(1)
  }
  _上下B(key){
    MyFuns.press("up", 30)
	  sleep(30)
    MyFuns.keyDown("down")
	  sleep(30)
	  this._down(2)
	  sleep(30)
    MyFuns.keyUp("down")
	  this._up(2)
  }
  _前前后B(key){
    local face := this._face.face()
    local back := this._face.back()
    MyFuns.press(face, 30)
    sleep(30)
    MyFuns.press(face, 30)
	  sleep(30)
    MyFuns.keyDown(back)
    sleep(30)
	  this._down(2)
	  sleep(60)
    MyFuns.keyUp(back)
    sleep(30)
	  this._up(2)
  }
  _前前后前B(key){
    local face := this._face.face()
    local back := this._face.back()
    MyFuns.press(face, 30)
    sleep(30)
    MyFuns.press(face, 30)
	  sleep(30)
    MyFuns.press(back, 30)
	  sleep(30)
    MyFuns.keyDown(face)
    sleep(30)
	  this._down(2)
	  sleep(60)
    MyFuns.keyUp(face)
    sleep(30)
	  this._up(2)
  }
  _后下前B(key){
    local face := this._face.face()
    local back := this._face.back()
    MyFuns.inputSkill([back, "down", face, this._keys[2]], [30, 30, 30, 30])
  }
  _后上前B(key){
    local face := this._face.face()
    local back := this._face.back()
    MyFuns.inputSkill([back, "up", face, this._keys[2]], [30, 30, 30, 30])
  }
  _左右摇(key){
    local thisKey :=  MyFuns.getHotkey(key) ;触发技能的热键
    loop {
      MyFuns.press("right", 20)
      sleep(20)
      MyFuns.press("left", 20)
    } until (MyFuns.waitKeyUp(thisKey, 20))
  }
  ;绿人瞬间闪电,参数其实可以更小一点,只是为了看起来更接近人手操作,
  ;效果也完全可以了
  _瞬电(key){
    this._press(2)
    sleep(70)
    this._press(3)
    sleep(70)
    this._上下B(key)    
  }
  _连发A(key){ ;尝试兼容连发时正好按住a追地,发现不行,参数固定为50,30算了
	  local vk := GetKeyVK(MyFuns.getHotkey(key))
    loop {
      this._down(1)
      sleep(50)
      this._up(1)
      sleep(30)
    } until (not MyFuns.getVkState(vk))
  }
  
  /* 重载宏接口
  */
  _setMacro(){
    static obm := ObjBindMethod ;函数名简写,制作对象绑定函数
    this.macroMap := OrderMap()
    this.macroMap["AB"] := obm(this, "_AB")
    this.macroMap["前A"] := obm(this, "_前A")
    this.macroMap["后前A"] := obm(this, "_后前A")
    this.macroMap["前前后B"] := obm(this, "_前前后B")
    this.macroMap["前前后前B"] := obm(this, "_前前后前B")
    this.macroMap["上下B"] := obm(this, "_上下B")
    this.macroMap["后上前B"] := obm(this, "_后上前B")
    this.macroMap["后下前B"] := obm(this, "_后下前B")
    this.macroMap["左右摇"] := obm(this, "_左右摇")
    this.macroMap["连发A"] := obm(this, "_连发A")
    this.macroMap["瞬电"] := obm(this, "_瞬电")
    this.macroMap["蓄力A"] := obm(this, "_蓄力A")
    this.macroArr := this.macroMap.getKeys()
  }

}

/* 制作忍者棒球专用UI
*/
class NbbatmanUI extends CommonUI {

  DEFAULT_HOTKEYS := "a,e,~c,f,~s,~x"
  EXE_ARRAY := [
    MyEmu.FBNEO64, MyEmu.FBAS, MyEmu.XZONE, MyEmu.MAME
  ]
  MACRO_PRIORITY := Map("瞬电", "p1") ;瞬电不可打断,优先级提高到1
  
  __New(macro){
    super.__New("忍者棒球", macro)
    this._preset := OrderMap()
    this._preset["绿"] := ["上下B", "后前A",  "左右摇", "瞬电", "连发A", "蓄力A"]
    this._preset["红"] := ["前前后前B", "后前A", "左右摇", "前A", "连发A", "蓄力A"] 
    this._preset["黄"] := ["后上前B", "后前A",  "左右摇", "前A", "连发A", "蓄力A"]
    this._preset["蓝"] := ["后下前B", "后前A",  "左右摇", "前A", "连发A", "蓄力A"]
  }
  
  /* 重写setup,更改可选的exe,读入预设
  */
  setup(){
    super.setup()
    this._myGui.opt("+AlwaysOnTop")
    this._myGui.show("x1100 y330")
    this.readPresetMenu("绿")
  }

}

/* 运行当前脚本
*/
if (A_ScriptName == "忍者棒球.2.ahk") {
  face := FaceDetector() ;方向检测对象
  macro := NbbatmanMacro(face, ["e","f"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;宏方案预设,用于菜单
  /*
  preset := Map(
    "红", ["前前后前B", "后前A", "左右摇", "前A", "连发A", "蓄力A"],
    "绿", ["上下B", "后前A",  "左右摇", "瞬电", "连发A", "蓄力A"],
    "黄", ["后上前B", "后前A",  "左右摇", "前A", "连发A", "蓄力A"],
    "蓝", ["后下前B", "后前A",  "左右摇", "前A", "连发A", "蓄力A"]
  )
  */
  ;新建界面并设定
  ui := NbbatmanUI(macro)
  ui.setup()
  ;ui._exeComboBox.Choose(MyEmu.FBASX64)
  ;ui._exeComboBox.Choose(MyEmu.MAME)
  ui._exeComboBox.Choose(MyEmu.FBNEO64)
  ui._gameKeyEdit.Text := "w,d,space"
  ui._hotkeyEdit.Text := "a,e,~c,f,~s,~x"
  ui._fpsEdit.Text := 12
  ui._testEdit.Text := "70,40,50,30"
  ui.readPresetMenu("绿")
}